/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: task_descriptor.cpp
 */

#include "task_descriptor.hpp"
#include "utils.hpp"

using namespace middleware;

//-----------------------------------------------------------------------------
// Constructors and destructor
/* Default constructor */
TaskDescriptor::TaskDescriptor() {
	this->_id = this->createID();
	this->_command = std::string();
	this->_link = TaskLinkage();
	(this->_link).machine_addr = std::string();
	(this->_link).network_inet_ip = std::string();
	(this->_link).network_inet_port = std::string();
	this->_type = kTaskExecutable;
}
/* Constructor 1 */
TaskDescriptor::TaskDescriptor(TaskType type, TaskCommand command) {
	this->_id = this->createID();
	this->_command = command;
	this->_link = TaskLinkage();
	(this->_link).machine_addr = std::string();
	(this->_link).network_inet_ip = std::string();
	(this->_link).network_inet_port = std::string();
	this->_type = type;
}
/* Constructor 2 */
TaskDescriptor::TaskDescriptor(TaskType type, TaskLinkage link) {
	this->_id = this->createID();
	this->_command = std::string();
	this->_link = link;
	this->_type = type;
}
/* Copy constructor */
TaskDescriptor::TaskDescriptor(const TaskDescriptor& task) {
	this->_id = task._id;
	this->_command = task._command;
	this->_link = task._link;
	this->_type = task._type;
}
/* Destructor */
TaskDescriptor::~TaskDescriptor() {
	// All members statically created.
}
//-----------------------------------------------------------------------------
// Private members
TaskId TaskDescriptor::createID() {
	return (TaskId)utils::GetRandomIntegralNumberInt(kMinTaskID, kMaxTaskID);
}
